<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <el-form-item label="关键信息" prop="name">
          <el-input v-model="queryParam.qry_name" placeholder="输入主题/标签"></el-input>
        </el-form-item>
        <el-form-item label="会议类型">
          <el-cascader v-model="meetType" :options="meetTypeList" filterable @change="handleMeetTypeChange" clearable></el-cascader>
        </el-form-item>
        <el-form-item label="会议时间">
          <el-date-picker v-model="meettimerange" type="daterange" value-format="yyyy-MM-dd" align="right" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" @change="meetTimeChange"> </el-date-picker>
        </el-form-item>
      </template>
    </tl-list-search>
    <!-- 工具栏 -->
    <tl-list-toolbar ref="toolbar" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :isDisplayAdd="false" :isDisplayDeleteBatch="false" :disableDeleteBatch="selectedRowKeys.length <= 0" :isDisplayExport="false">
      <template slot="left-btn"><el-button style="float: right; position: absolute; right: 140px" class="filter-item" type="text" icon="el-icon-plus" @click="openAddDialog('editForm')">补录会议纪要</el-button></template>
      <template slot="right-btn"></template>
    </tl-list-toolbar>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
<!--        <el-table-column type="selection" width="55px" fixed="left"></el-table-column>-->
        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
        <el-table-column prop="name" label="会议主题" min-width="180px" sortable="custom" sort-by="name" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispmeettypeid" label="会议类型" width="200px" sortable="custom" sort-by="meettypeid" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="begintime" label="会议开始时间" width="170px" sortable="custom" sort-by="begintime" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="endtime" label="会议结束时间" width="170px" sortable="custom" sort-by="endtime" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="keywords" label="会议标签" width="180px" sortable="custom" sort-by="keywords" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispstate" label="状态" width="100px" sortable="custom" sort-by="state" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="launchusername" label="会议发起人" width="100px" sortable="custom" sort-by="launchusercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="操作" width="110px" v-slot="scope" fixed="right">
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item v-if="!isReadOnly" icon="el-icon-edit" @click.native="openEditDialog('editForm', scope.row.id)">编辑</el-dropdown-item>
              <el-dropdown-item v-if="!isReadOnly" icon="el-icon-delete" @click.native="doLimitDelete(scope.row)">删除</el-dropdown-item>
              <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm" @refresh="doRefresh"></tl-edit>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import tlEdit from './edit'
import tlRefMeetType from '../meetTypeManage/refMeetType'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
export default {
  name: 'meetRecord',
  mixins: [mixin_list],
  components: { tlEdit, tlRefMeetType },
  data() {
    return {
      description: '会议资料-列表查询',
      urlPrefix: '/meet/record/',
      url: {
        // queryCodeList: '/meet/record/dataCodeList'
        queryMeetTypeList: '/meet/typeManage/queryTreeList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'id',
        sord: 'desc'
      },
      queryParam: { qry_isall: '0' },
      meetType: [],
      meetTypeList: [],
      meettimerange: '',
      isReadOnly: false,
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              end.setTime(end.getTime() + 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              end.setTime(end.getTime() + 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              end.setTime(end.getTime() + 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      },
      // header显示
      isHeaderDisplay: false,
      compCreated: false
    }
  },
  methods: {
    /** 限制删除*/
    doLimitDelete(data) {
      if (data.state === 1) {
        this.$tap.alert('发布的会议资料不允许删除！', 'warning')
        return
      }
      this.doDelete(data.id)
    },
    /** 批量删除 */
    doLimitDeleteBatch() {
      let isExistPublish = false
      if (this.selectedRowKeys.length <= 0) {
        this.$tap.alert('请选择记录！', 'warning')
        return
      } else {
        for (var index = 0; index < this.selectionRows.length; index++) {
          if (this.selectionRows[index].state === 1) {
            isExistPublish = true
          }
        }
      }
      if (isExistPublish === true) {
        this.$tap.alert('发布的会议资料不允许删除！请重新选择', 'warning')
        return
      } else {
        this.doDeleteBatch()
      }
    },
    handleMeetTypeChange(value) {
      this.queryParam.qry_meettypeid = value[value.length - 1]
    },
    meetTimeChange(value) {
      if (value == null) {
        this.queryParam.qry_begindatetime = ''
        this.queryParam.qry_enddatetime = ''
      } else {
        this.queryParam.qry_begindatetime = value[0]
        this.queryParam.qry_enddatetime = value[1]
      }
    }
  },
  mounted() {
    this.$nextTick(_ => {
      if (this.$route.query && this.$route.query.sourceid && this.$route.query.sourceid !== 'undefined') {
        if (this.$route.query.id && parseInt(this.$route.query.id) > 0) {
          if (parseInt(this.$route.query.readable) === 1) {
            this.openViewDialog('editForm', this.$route.query.id)
          } else {
            this.openEditDialog('editForm', this.$route.query.id)
          }
        } else {
          this.openAddDialog('editForm')
        }
        this.$refs.editForm.ehrsourceid = this.$route.query.sourceid
        if (parseInt(this.$route.query.audioable) === 1) {
          this.$refs.editForm.changeTabToAudio()
        }
        if (parseInt(this.$route.query.readable) === 1) {
          this.isReadOnly = true
        }
        this.$refs.editForm.fromehr = '1'
      }
    })
  },
  activated() {
    if (this.compCreated) {
      this.loadData({})
    }
  },
  created() {
    /** 查询树 */
    getAction(this.url.queryMeetTypeList, { isAddRoot: false }).then(res => {
      if (res.success) {
        let reg = new RegExp('id', 'g') // g代表全部
        this.meetTypeList = JSON.parse(JSON.stringify(res.result.dataList).replace(reg, 'value'))
      }
    })
    this.$nextTick(() => {
      this.compCreated = true
    })
  }
}
</script>

<style scoped></style>
